package org.zfes.snowier.cloud.zbss.tts.config;

import java.io.File;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class TTSWebMvcConfigurer   implements WebMvcConfigurer  {

	
	   @Override
	    public void addResourceHandlers(ResourceHandlerRegistry registry) {
		   String audioSave=AppCtxUtil.cfg().getBean(TssConfig.class).getAudioSavePath();
	        //配置静态资源处理
		   //registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
		   registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
		   registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
	       registry.addResourceHandler("/audio/**").addResourceLocations("file:///"+audioSave+File.separator+"");
	    }
//	   @Bean  
//		 public FilterRegistrationBean filterRegistrationBean2() {  
//			   FilterRegistrationBean filterRegistration = new FilterRegistrationBean();  
//			   filterRegistration.setOrder(Ordered.HIGHEST_PRECEDENCE);
//			   filterRegistration.setFilter(corsFilter());
//			   filterRegistration.addUrlPatterns("/*");
//			   filterRegistration.setName("crosFilter");
//			   return filterRegistration;  
//		} 
//		 @Bean
//		 public CorsFilter corsFilter() {
//		        final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
//		        final CorsConfiguration corsConfiguration = new CorsConfiguration();
//		        corsConfiguration.setAllowCredentials(true);
//		        corsConfiguration.addAllowedOrigin("*");
//		        corsConfiguration.addAllowedHeader("*");
//		        corsConfiguration.addAllowedMethod("*");
//		        urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
//		        return new CorsFilter(urlBasedCorsConfigurationSource);
//		    }
}
